package jackson.src.day03.betterChar;

/*
 * Author: JacksonCoder
 * FileName: test
 * Version: 1.0.0
 */
public class test {
    public static void main(String[] args) {
        String s1 = "Hello";

        String s2 = new String(new char[] {'H', 'e', 'l', 'l', 'o'});

        String s = "Hello";
        System.out.println(s);
        s = s.toUpperCase();
        System.out.println(s);

        // 字符串比较
        System.out.println(s1 == s);
        System.out.println(s1.equals(s));
        System.out.println("================");
        System.out.println(s1.equalsIgnoreCase(s));
        System.out.println(s1.compareTo(s)); // 比较字符串大小
        System.out.println("================");

        boolean flag = s.contains("ll");
        System.out.println(flag);
        System.out.println("======== 搜索子串的更多的例子： ========");

        System.out.println("Hello".indexOf("l"));
        System.out.println("Hello".lastIndexOf("l"));
        System.out.println("Hello".startsWith("He"));
        System.out.println("Hello".endsWith("lo"));
        System.out.println("======= 提取子串的例子： =========");
        System.out.println("Hello".substring(2));
        System.out.println("Hello".substring(2,4));

        System.out.println("======= 去除首尾空白字符 =========");
        System.out.println(" \t Hello \r\n ".trim());   // trim()并没有改变字符串的内容，而是返回了一个新字符串。

        System.out.println("\u3000Hello\u3000".strip());  //  strip()方法也可以移除字符串首尾空白字符。它和trim()不同的是，类似中文的空格字符\u3000也会被移除：
        System.out.println(" Hello ".stripLeading());
        System.out.println(" Hello ".stripTrailing());

        System.out.println("========String还提供了isEmpty()和isBlank()来判断字符串是否为空和空白字符串：=========");
        System.out.println("".isEmpty());    // true，因为字符串长度为0
        System.out.println("   ".isEmpty());  // false，因为字符串长度不为0
        System.out.println(" \n ".isBlank());  // true，因为只包含空白字符
        System.out.println(" Hello ".isBlank());   // false，因为包含非空白字符

        String so = "Hi %s, your score is %d!";
//        System.out.println(so.formatted("Alice", 80));
        System.out.println(String.format("Hi %s, your score is %.2f!", "Bob", 59.5));

        System.out.println("===================");
        System.out.println(String.valueOf(123));
        System.out.println(String.valueOf(45.67));
        System.out.println(String.valueOf(true));
        System.out.println(String.valueOf(new Object()));

        System.out.println("===================");

        int n1 = Integer.parseInt("123"); // 123
        int n2 = Integer.parseInt("ff", 16); // 按十六进制转换，255

        System.out.println(n1);
        System.out.println(n2);
        System.out.println("===================");

        char[] cs = "Hello".toCharArray();
        String sa = new String(cs);
        System.out.println(sa);
        cs[0] = 'X';
        System.out.println(sa);


    }
}
